package com.cbh.amadeus.server.domain;

import com.cbh.amadeus.server.utils.TopicChannelManage;
import io.netty.channel.Channel;
import lombok.Data;

import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author ChenBiHui
 * @date 2025/5/2
 */
@Data
public class ChannelModel {

    /**
     * 订阅者
     */
    private final Channel channel;

    /**
     * 订阅者名称
     */
    private final String name;

    /**
     * 订阅者原始名称
     */
    private final String origin;

    /**
     * 订阅者关注主题
     */
    private final Set<String> topics = ConcurrentHashMap.newKeySet(64);

    /**
     * 自限锁
     */
    private final ReentrantLock lock = new ReentrantLock();

    public ChannelModel(Channel channel, String name) {
        this.channel = channel;
        this.name = name;
        this.origin = TopicChannelManage.origin(name);
    }
}
